# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible


# Create your models here.

@python_2_unicode_compatible
class Game(models.Model):
    """
    游戏表
    pt_type:  游戏平台：大陆静默，大陆sy
    game_type:   游戏类别：安卓，IOS
    name:游戏名称
    client_id:游戏client_id
    """

    GAME_TYPE = {
        ('android', u'安卓'),
        ('iOS', 'IOS')
    }
    game_type = models.CharField("类别", choices=GAME_TYPE, max_length=64)
    name = models.CharField("游戏名称", max_length=64)
    client_id = models.CharField("游戏id", max_length=64)
    game_ext = models.TextField("游戏信息", max_length=1024, blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['name', ]


@python_2_unicode_compatible
class TestDetail(models.Model):
    RESULT_CHOICES = {
        ('0', u'不通过'),
        ('1', u'通过'),
        ('2', u'暂不接入'),
        ('3', u'忽略'),

    }
    PT_CHOICES = {
        ('jm', u'靜默版'),
        ('sy', u'4399sy')
    }
    CHARGE_CHOICES = {
        ('0', u'非充值包'),
        ('1', u'充值包'),
        ('2', u'动态充值包'),
    }
    game = models.ForeignKey(Game)
    appver = models.CharField(max_length=64)
    pt_type = models.CharField("平台", choices=PT_CHOICES, max_length=64,
                               blank=True, null=True,
                               default="jm")
    suid = models.CharField(max_length=64, blank=True, null=True,
                            default="None")
    sy_sdk = models.CharField(max_length=64, blank=True, null=True,
                              default="None")
    fn_sdk = models.CharField(max_length=64, blank=True, null=True,
                              default="None")
    vcode = models.CharField(max_length=64, blank=True, null=True,
                             default="None")
    device_id = models.CharField(max_length=64, blank=True, null=True,
                                 default="None")
    case_info = models.TextField(max_length=1024, blank=True, null=True)
    plat_channel = models.CharField(max_length=64, blank=True, null=True,default="None")
    sy_channel = models.CharField(max_length=64, blank=True, null=True,default="None")
    result = models.CharField(choices=RESULT_CHOICES,
                              max_length=64)  # {{ obj.get_result_display  }}
    add_date = models.DateTimeField(auto_now_add=True)
    modify_date = models.DateTimeField(auto_now=True)
    recharge = models.CharField(max_length=64, choices=CHARGE_CHOICES,
                                blank=True, null=True,
                                default="1")
    package = models.CharField(max_length=64, blank=True, null=True,
                               default="None")
    md5 = models.CharField(max_length=64, blank=True, null=True, default="None")
    test_ext = models.TextField(max_length=1024, blank=True, null=True)
    creator = models.CharField(max_length=64, blank=True, null=True)

    def __str__(self):
        return self.game.name

    class Meta:
        ordering = ['game', '-add_date']


@python_2_unicode_compatible
class YDProject(models.Model):
    project_name = models.CharField(max_length=64)
    project_id=models.CharField(max_length=64)

    def __str__(self):
        return self.project_name

@python_2_unicode_compatible
class YDGame(models.Model):
    game = models.ForeignKey(Game,null=True, blank=True,on_delete=models.CASCADE)
    project_id = models.ForeignKey(YDProject,null=True, blank=True)


    def __str__(self):
        return self.game.client_id